#pragma once
#include "noncopyable.h"
#include <functional>
#include <thread>
#include <memory>
#include <unistd.h>
#include <string>
#include <atomic>

class Thread : noncopyable {
    public:
        using ThreadFunc = std::function<void()>;

        explicit Thread(ThreadFunc, const std::string &name = std::string());
        ~Thread();

        void start();
        void join();

        bool started() const {return started_; }
        pid_t tid() const { return tid_; }
        const std::string &name() const { return name_; }

        static int numCreated() { return numCreated_; }//标识现在创建了多少线程

    private:
        void setDefaultName();//设置线程的默认名字

        bool started_;
        bool joined_;
        std::shared_ptr<std::thread> thread_;//指向线程的智能指针
        pid_t tid_;
        ThreadFunc func_;//线程回调函数
        std::string name_;
        static std::atomic_int numCreated_;
    

};  